<?php
session_start();

if (!isset($_GET['redirect']) || empty($_GET['redirect'])) {
    die("错误的请求");
}

$url = $_GET['redirect'];

if (isset($_SESSION['username'])) {
    //当前用户已登录，重定向回原路径并返回token
    header("Location:{$url}?token={$_SESSION['username']}");
    exit;
}
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<body>
<form action="login.php" method="post">
    <input type="text" name="username">
    <input type="hidden" name="redirect" value="<?=$url?>" />
    <input type="submit" value="提交">
</form>
</body>
</html>
